package com.controller;

import com.alibaba.fastjson.JSON;
import com.entity.Course;
import com.entity.Grade;
import com.entity.Student;
import com.service.CourseService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

@RestController
public class CourseController {

    @Autowired
    private CourseService courseservice;

    @RequestMapping("/abc")
    public List<Course> getCourse(){
        return courseservice.find();
    }

    @RequestMapping("/addGrade")
    public String addGrade(@RequestBody Course grade){
        int i=courseservice.addGrade(grade);
        return i>0?"success":"error";
    }

    @RequestMapping("/deleteGrade")
    public String deleteGrade(String sno,String cno){
        int i=courseservice.deleteGrade(sno,cno);
        return i > 0 ? "success":"error";
    }

//    @RequestMapping("/getupdat")
//    public String getUpdateGrade(String sno,String cno){
//        Grade grade=courseservice.getUpdateGrade(sno,cno);
//        String string1 = JSON.toJSONString(grade);
//        return string1;
//        //此处有错误
//    }

    @RequestMapping("/editGrade")
    public String editGrade (@RequestBody Grade grade){
        int i=courseservice.editGrade(grade);
        return i>0?"success":"error";
    }
}
